package vip.kqsy.cloud.blog.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.kqsy.cloud.blog.server.pojo.dto.InteractiveOptionDTO;
import vip.kqsy.cloud.blog.server.service.BlogInteractiveService;
import vip.kqsy.cloud.core.security.user.KqsyUserContext;
import vip.kqsy.cloud.core.web.res.R;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 博客交互表 前端控制器
 * </p>
 *
 * @author cenjunjie
 * @since 2023-05-03
 */
@RestController
@RequestMapping("/blogInteractive")
@Api(tags = "博客交互")
@Valid
@RequiredArgsConstructor
public class BlogInteractiveController {

    private final BlogInteractiveService blogInteractiveService;

    @PostMapping("like")
    @ApiOperation("点赞")
    public R<Void> like(@Parameter(description = "博客ID") @NotNull Long blogId) {
        blogInteractiveService.like(blogId, KqsyUserContext.getUser().getId());
        return R.ok();
    }

    @PostMapping("option")
    @ApiOperation("互动操作")
    public R<Void> option(@Valid InteractiveOptionDTO dto) {
        dto.setUserId(KqsyUserContext.getUser().getId());
        blogInteractiveService.option(dto);
        return R.ok();
    }

}
